package com.aat.dxfy.execOnline;

import java.io.*;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class DynamicCompileTest {
	public static void main(String[] args) throws Exception {
		// 编译程序
		JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
		int res = javaCompiler.run(null, null, null, "-d", "E:\\", "E:\\JarTest.java");
		System.out.println(res == 0 ? "恭喜编译成功" : "对不起编译失败");
		// 运行程序
		Runtime run = Runtime.getRuntime();
		Process process = run.exec("java  -cp E:\\com\\aat\\dxfy\\cmd\\JarTest");
		InputStream in = process.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		String info = "";
		while ((info = reader.readLine()) != null) {
			System.out.println(info);
		}
	}
}
